package main

import (
	"fmt"
	"strconv"
)

/**
执行用时：0 ms, 在所有 Go 提交中击败了100.00%的用户
内存消耗：3.2 MB, 在所有 Go 提交中击败了49.85%的用户
 */
func multiply(num1 string, num2 string) string {

	n, m := len(num1), len(num2)
	A, B := make([]int, n), make([]int, m)
	for i := n - 1; i >= 0; i-- { A[n - 1 - i] = int(num1[i] - '0') }
	for i := m - 1; i >= 0; i-- { B[m - 1 - i] = int(num2[i] - '0') }

	C := make([]int, n + m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			C[i + j] += A[i] * B[j]
		}
	}

	for i, t := 0, 0; i < n + m; i++ {
		t += C[i]
		C[i] = t % 10
		t /= 10
	}

	k := len(C) - 1
	for k > 0 && C[k] == 0 { k-- }
	res := ""
	for k >= 0 {
		res += strconv.Itoa(C[k])
		k--
	}
	return res
}

func main() {

	fmt.Println(multiply("123", "456"))
}
